
/******************************************************************************\
|    Title:        	 Table E4: Regression Models for Switching Below Threshold |
						and Demotions in Rank								   |
|    Date:         	 July 2023	                                         	   |
|    Author:         Elisa Wirsching	      							       |
\******************************************************************************/

clear all
set more off, permanently
numlabel, add
set maxvar 32000

use congress_yearly.dta, clear

* Now analyze whether they are more likely to see demotions
* A lower rank measures more senior positions in Ritchie and You (2021)
xtset stafferid year
sort stafferid year
gen demotion = max_rank[_n-1] < max_rank & stafferid[_n-1]==stafferid & year[_n-1]==year-1
replace demotion = . if max_rank==.

bysort stafferid: egen temp = total(switchtouncovered_treatment) if posttreat==1 // only switchers after HLOGA

* regression of demotion on switching
xtreg demotion switchtouncovered_treatment if temp>0, fe cluster(stafferid)
summarize demotion if e(sample)==1
estadd scalar ymean = r(mean) 
est store mod1
estadd local fixed "Yes" , replace

xtreg demotion switchtouncovered_treatment i.year if temp>0, fe cluster(stafferid)
summarize demotion if e(sample)==1
estadd scalar ymean = r(mean) 
est store mod2
estadd local fixed "Yes" , replace

esttab mod* using "TABLED4.csv", replace ///
	b(3) se(3) star(* .05 ** .01 *** 0.001) ///
	nomtitles ///
	stats(fixed ymean N N_g r2, fmt(0 3 0 0 3) labels("Staffer FE" "Mean of DV"  "Observations" "Number of staffers" "R2"))  ///
    label parentheses nogaps nolines noeqlines ///
    noomitted nodepvars nobaselevels indicate("Year FE = *.year") nonotes noconstant
